package com.csair.platform.cit.service.controller;

import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSON;
import com.csair.invoice.common.base.vo.JsonResult;
import com.csair.platform.cit.facade.CitWgqyGridApi;
import com.csair.platform.cit.facade.model.citwgqyGrid.sy.vo.CitWgqyGridItemVo;
import com.csair.platform.cit.facade.model.citwgqyGrid.sy.vo.CitWgqyGridRequest;
import com.csair.platform.cit.service.biz.ICitWgqyGridService;
import com.csair.platform.cit.service.core.CheckDataPermission;
import com.csair.platform.cit.service.entity.CitWgqyGrid;
import com.csair.platform.usercenter.facade.model.user.UserVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author zhengxincheng
 */
@Api(tags = "居民企业参股外国企业信息报告")
@Slf4j
@RestController
public class CitWgqyGridController extends BaseController implements CitWgqyGridApi {

    @Autowired
    ICitWgqyGridService iCitWgqyGridService;

    @CheckDataPermission
    @Override
    public JsonResult save(@RequestBody CitWgqyGridItemVo cgq) {
        log.info("居民企业参股外国企业信息报告-保存:{}",JSON.toJSONString(cgq));
        UserVo user = getCurrentUser();
        Assert.isTrue(!Objects.isNull(cgq.getCitWgqyGrid()),"主表数据不能是null");

        cgq.getCitWgqyGrid().setCreateBy(user.getCreateBy());
        iCitWgqyGridService.save(cgq);
        return JsonResult.success();
    }

    @CheckDataPermission
    @Override
    public JsonResult query(@RequestBody CitWgqyGridRequest params) {
        log.info("居民企业参股外国企业信息报告-query:{}", JSON.toJSONString(params));
        Page<CitWgqyGrid> pageData = iCitWgqyGridService.query(params);
        return JsonResult.success(pageData.getContent(),pageData.getTotalElements());
    }
    @CheckDataPermission
    @Override
    public JsonResult queryById(@PathVariable Long id) {
        return JsonResult.success(iCitWgqyGridService.queryById(id));
    }

    @CheckDataPermission
    @Override
    public JsonResult deleteById(@PathVariable Long id){
        log.info("居民企业参股外国企业信息报告-deleteById:{}", JSON.toJSONString(id));
        iCitWgqyGridService.deleteById(id);
        return JsonResult.success();
    }
}
